package schoolDemo3;
//重载构造方法

class CyLinder7_5{
    private double radius;
    private int height;
    private double pi=3.14;
    String color;

    public CyLinder7_5(){
        this.radius=2;
        this.color="红色";
        this.height=5;
    }
    public CyLinder7_5(double r,int h,String c){
        radius=r;
        height=h;
        color=c;
    }
    double area(){ return pi*radius*radius;}
    double volume(){ return area()*height;}
    public void setColor(){
        System.out.println("该圆柱的颜色为："+this.color);
    }
}
public class App7_5 {
    public static void main(String[] args) {
        //这里调用无参数的构造方法来初始化成员变量
        CyLinder7_5 volu1=new CyLinder7_5();
        System.out.println("该圆柱体1的底面积为："+volu1.area());
        System.out.println("该圆柱体1的体积为："+volu1.volume());

        //利用有参数的构造方法来初始化
        CyLinder7_5 volu2=new CyLinder7_5(9.5,7,"蓝色");
        System.out.println("该圆柱体2的底面积为："+volu2.area());
        System.out.println("该圆柱体2的体积为："+volu2.volume());
    }
}
